package com.yanqu.road.server.cmd.banquet.party;

import com.yanqu.road.pb.banquet.BanquetProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.server.protocol.Protocol;
import io.netty.channel.ChannelHandlerContext;

import java.util.List;

@Cmd(code = GameProtocol.S_CROSS_PARTY_JOIN_NOTICE_ALL, desc = "")
public class CrossJoinNoticeAllCmd implements Command {
    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception {
        BanquetProto.CrossPartyNoticeAllMsg syncMsg = BanquetProto.CrossPartyNoticeAllMsg.parseFrom(packet.getBytes());
        List<Long> userIdList = syncMsg.getUserIdList();
        for (Long userId : userIdList) {
            GamePlayer player = GamePlayerMgr.getPlayer(userId);
            if (player != null) {
                Long pingTime = player.getLastPingTime();
                Long nowTime = System.currentTimeMillis();
                if (nowTime - pingTime < 5 * 1000) {//ping小于5秒才同步
                    player.sendPacket(Protocol.U_BANQUET_MEMBER_SYNC, syncMsg.getMsg().toBuilder());
                }
            }
        }
    }
}
